package com.relytosoft.mizar.media.system.services.service.impl;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.relytosoft.mizar.media.system.api.entity.SysRelatedPlatform;
import com.relytosoft.mizar.media.system.services.mapper.SysRelatedPlatformMapper;
import com.relytosoft.mizar.media.system.services.service.SysRelatedPlatformService;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * SysRelatedPlatformServiceImpl
 *
 * @Author SunLi
 * @Date: 2022/4/8 9:30
 * @Version 1.0
 */
@Service
public class SysRelatedPlatformServiceImpl extends ServiceImpl<SysRelatedPlatformMapper, SysRelatedPlatform> implements SysRelatedPlatformService {

    @Override
    public SysRelatedPlatform getOneByQuery(SysRelatedPlatform sysRelatedPlatform) {
        LambdaQueryWrapper<SysRelatedPlatform> wrapper = Wrappers.lambdaQuery();
        //查询指定第三方平台
        if (!StrUtil.isEmptyIfStr(sysRelatedPlatform.getPlatformName())) {
            wrapper.eq(SysRelatedPlatform::getPlatformName, sysRelatedPlatform.getPlatformName());
        }
        //查询已同步
        if(sysRelatedPlatform.getIsSync()!=null){
            wrapper.eq(SysRelatedPlatform::getIsSync, sysRelatedPlatform.getIsSync());
        }
        //查询指定同步类型
        wrapper.eq(SysRelatedPlatform::getType,sysRelatedPlatform.getType());
        //查询指定系统ID
        wrapper.eq(SysRelatedPlatform::getOwnId,sysRelatedPlatform.getOwnId());
        return this.getOne(wrapper,false);
    }


    @Override
    public SysRelatedPlatform getRelatedPlatform(Integer type, String platformName, Integer id, int isSync) {
        SysRelatedPlatform search=new SysRelatedPlatform();
        search.setPlatformName(platformName);
        search.setOwnId(id);
        search.setType(type);
        search.setIsSync(isSync);
        return this.getOneByQuery(search);
    }

    @Override
    public List<SysRelatedPlatform> selectRelatdPlatformList(Integer type, String platformName) {
        LambdaQueryWrapper<SysRelatedPlatform> wrapper = Wrappers.lambdaQuery();
        //查询指定第三方平台
        if (!StrUtil.isEmptyIfStr(platformName)) {
            wrapper.eq(SysRelatedPlatform::getPlatformName, platformName);
        }
        //查询指定同步类型
        wrapper.eq(SysRelatedPlatform::getType,type);
        //查询指定同步类型
        wrapper.eq(SysRelatedPlatform::getIsSync,1);
        return this.list(wrapper);
    }
}
